package org.study.event.core.transaction.manager;

import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;
import org.study.event.core.common.EventMessage;
import org.study.event.core.transaction.AbstractTranactionListenerManager;

/***
 * Spring 事务监听管理默认实现
 * 
 * @author 陈波
 *
 */
public class DefaultTranactionListenerManager extends AbstractTranactionListenerManager
		implements ApplicationEventPublisherAware {

	/***
	 * 事件监听发布
	 */
	private ApplicationEventPublisher applicationEventPublisher;

	@Override
	public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
		this.applicationEventPublisher = applicationEventPublisher;
	}

	/***
	 * 覆盖父类的方法加上注解
	 */
	@Override
	@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
	public void afterCommit(EventMessage message) {
		super.afterCommit(message);
	}

	@Override
	@TransactionalEventListener(phase = TransactionPhase.AFTER_ROLLBACK)
	public void afterRollBack(EventMessage message) {
		super.afterRollBack(message);
	}

	@Override
	@TransactionalEventListener(phase = TransactionPhase.BEFORE_COMMIT)
	public void beforeCommit(EventMessage message) {
		super.beforeCommit(message);
	}

	@Override
	@TransactionalEventListener(phase = TransactionPhase.AFTER_COMPLETION)
	public void afterCommpetion(EventMessage message) {
		super.afterCommpetion(message);
	}

	@Override
	public void pushTransactionEvent(EventMessage message) {
		applicationEventPublisher.publishEvent(message);
	}

}
